/**
 * Created by gitbong on 8/29/15.
 */
var app = (function () {
    var startP = {};
    var currP = {};

    var _ins = {
        init: function () {
			$("#yk-play-btn").bind('click',function(){
                var vid = $(this).attr('vid') * 1;
                _ins.initVid(vid);
            });

            $('#section1 .vid-btn').bind('click',function(){
                var vid = $(this).attr('vid') * 1;
                _ins.initVid(vid);
            })

            $('#pop-ctn .close-btn').bind('click',function(){
                $('#pop-ctn').hide();
                $('#player').empty();
                //$('body').css('overflow','auto');
            });

            setInterval(function(){
                //console.log($('#pop-ctn').css('display'));
                if( $('#pop-ctn').css('display') == 'block' ){
                    $(window).addClass('noscroll');
                    $('body').addClass('noscroll');
                    //console.log(1)
                }else{
                    //console.log(2)
                    $(window).removeClass('noscroll');
                    $('body').removeClass('noscroll');
                    //$(window).css('overflow','auto');
                }
            },1000);
        },
        initVid: function (id_) {
            var videoW = 600;               //视频宽
            var videoH = 330;               //视频高

            var tkArr = ['TVC',"产品","预热"];

            var urlArr = [                  //首页三支视频地址
                prdMediaPath + '/V8/media/endurance.mp4',   //V8续航 0
                prdMediaPath + '/V8/media/design.mp4',   //V8工艺 1
                prdMediaPath + '/V8/media/camera.mp4',   //V8拍照 2
				prdMediaPath + '/V8/media/gallary.mp4',   //V8图集 3
				prdMediaPath + '/mate8/media/MATE8hot.mp4',   //mate8观看热门 4
				prdMediaPath + '/mate8/media/MATE8TVC.mp4',   //mate8TVC 5
				prdMediaPath + '/mate8/media/MATE8product.mp4'    //mate8产品视频 6
			];
            //
            $('#pop-ctn').show();
            $('#player').empty();
            //$('body').css('overflow','hidden');
			 jwplayer('player').setup({
					file: urlArr[id_],
					width: '100%',
					height: '100%',
					autostart: true
				});
				
				gb.window.sgResize.add(function () {
					var sw = gb.window.getWidth();
					var sh = gb.window.getHeight();
					var r = videoW / videoH;
					var sr = sw / sh;
					if (sr > r) {
						$('.vid-ctn').css({height: sh, width: sh * r, marginLeft: -sh * r / 2,marginTop:-sh/2});
					} else {
						$('.vid-ctn').css({height: sw/r, width: sw, marginLeft:-sw/2,marginTop:-sw/r/2});
					}
				})
				gb.window.doResize();
        }
    };


    $(function () {
        _ins.init();

		/* IE版本判断*/
        var isIE = !!window.ActiveXObject; 
        var isIE6 = isIE && !window.XMLHttpRequest; 
        var isIE8 = isIE && !!document.documentMode; 
        var isIE7 = isIE && !isIE6 && !isIE8;  
        if(isIE6||isIE7||isIE8){
            $('#section1 .vid-btn').css('display','none');
            $('#video-elment').addClass("hide");
        }
    });

    return _ins;
})();